package com.aaa.vegetablemarketexpress.controller;

import com.aaa.vegetablemarketexpress.entity.Brand;
import com.aaa.vegetablemarketexpress.entity.Notice;
import com.aaa.vegetablemarketexpress.service.BrandService;
import com.aaa.vegetablemarketexpress.service.NoticeService;
import com.aaa.vegetablemarketexpress.util.Page;
import com.aaa.vegetablemarketexpress.util.Result;
import com.aaa.vegetablemarketexpress.util.ResultUtil;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @FileName: NoticeController
 * @Description:
 * @Author: 张钰哲
 * @CreateTime: 2025/9/13 15:18
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("notice")
@Log4j2
public class NoticeController {
    @Resource
    private NoticeService noticeService;
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<Notice> page) {
        log.info("开始执行分页查询");
        PageInfo pageInfo = noticeService.queryByPage(page);
        log.info("分页查询结束");
        return ResultUtil.success(pageInfo);
    }
    /**
     * 根据id查询
     * @param noticeId
     * @return
     */
    @GetMapping("getNoticeById")
    public Result getNoticeById(Long noticeId) {
        return ResultUtil.success(noticeService.getNoticeById(noticeId));
    }

    /**
     * 添加
     * @param notice
     * @return
     */
    @PostMapping("add")
    public Result addNotice(@RequestBody Notice notice) {
        return ResultUtil.success(noticeService.addNotice( notice));
    }

    /**
     * 更新
     * @param notice
     * @return
     */
    @PostMapping("update")

    public Result update(@RequestBody Notice notice) {
        return ResultUtil.success(noticeService.updateNotice( notice));
    }

    /**
     * 根据id删除
     * @param noticeId
     * @return
     */
    @DeleteMapping("deleteNoticeById")
    public Result deleteNoticeById(Long noticeId) {
        return ResultUtil.success(noticeService.deleteNoticeById( noticeId));
    }
@PutMapping("view")
    public Result view(@RequestParam Long noticeId) {
    Notice view = noticeService.view(noticeId);
    return ResultUtil.success(view);
    }
}
